<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>用户注册</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 20px;
        }

        h1 {
            text-align: center;
            color: #333;
        }

        form {
            max-width: 400px;
            margin: 0 auto;
            background-color: #fff;
            padding: 20px;
            border-radius: 5px;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
        }

        label {
            display: block;
            margin-bottom: 10px;
        }

        input[type="text"],
        input[type="password"],
        input[type="number"],
        select {
            width: 100%;
            padding: 10px;
            margin-bottom: 15px;
            border-radius: 5px;
            border: 1px solid #ccc;
        }

        input[type="submit"] {
            width: 100%;
            background-color: #4CAF50;
            color: white;
            padding: 10px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }

        input[type="submit"]:hover {
            background-color: #45a049;
        }
    </style>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<h1>注册新用户</h1>
<form action="register" method="post" id="registerForm">
    <label for="username">用户名:</label>
    <input type="text" id="username" name="username" required placeholder="输入用户名">

    <label for="password">密码:</label>
    <input type="password" id="password" name="password" required placeholder="输入密码">

    <label for="confirm_password">确认密码:</label>
    <input type="password" id="confirm_password" name="confirm_password" required placeholder="再次输入密码">


    <label for="email">邮箱:</label>
    <input type="text" id="email" name="email"  placeholder="输入邮箱">

    <input type="submit" value="注册">
</form>
<script>
    $(document).ready(function() {
        $('#registerForm').submit(function(event) {
            event.preventDefault(); // 阻止表单的默认提交行为
            // 收集表单数据
            var formData = $(this).serialize();
            $.ajax({
                url: '/user/register', // 请求的 URL
                type: 'POST', // 请求类型
                data: formData, // 发送的数据
                dataType: 'json', // 预期的服务器响应的数据类型
                success: function(response) {
                    if (response.code==200){
                        window.location.href = 'login.html';
                    }
                },
            });
        });
    });
</script>
</body>
</html>